<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/WEB-INF/component/commonTagLib.jsp" %>

<!DOCTYPE html>
<html>
<head>
    <title>收件箱</title>
    <%@ include file="/WEB-INF/component/commonCSS.jsp" %>
</head>
<body class="skin-blue-light sidebar-mini fixed skin-blue-light-frame">
							
    <section class="content-header">
        <h1>收件箱</h1>
        <ol class="breadcrumb">
            <li><a href="${ctx}/home.jsp"><i class="fa fa-home"></i><spring:message code="message.lable.first"/></a></li>
            <li class="active"><a href="#">消息管理</a></li>
            <li class="active"><a href="#">收件箱</a></li>
        </ol>
    </section>
    
    <section class="content">
       <div class=" box box-success">
		<div class="box-body"  >
		    <div class="input">
		       <div class="textalign1">消息标题：</div>
               <div class="boxinput">
                        <input type="text" class="textinput" id="titleTitle" placeholder="消息标题" maxlength="64"/>
               </div>	
               <div class="textalign">消息类型：</div>
               <div class="boxinput">
                        <select class="textinput " name="type" id="schType">
                            <option value=""><spring:message code="message.select.option"/></option>
                            <option value="1">系统消息</option>
                             <option value="2">用户消息</option>
                        </select>
               </div>	   
		   
               <div class="textalign1">
		             <button type="button" class="btn btn-success btn-sm" onclick="search();" id="selectDicCompType"><spring:message code="message.button.seachSpacing"/></button>
		       </div>
		    </div>
		    </div>
		</div>
        
        <table class="jqgrid" id="gridlist"></table>
        <div id="gridpage"></div>
      
             <div class="modal fade" id="backModal" tabindex="-1" >
            <div class="modal-dialog">
                <div class="modal-content">
                    <div class="modal-header bg-primary">
                        <button type="button" class="close" data-dismiss="modal" ><span >&times;</span></button>
                        <h5 class="modal-title" id="exampleModalLabel">消息回复</h5>
                    </div>
                    <div class="modal-body">
                  <form action="${ctx}/sysMessage/saveOrUpDate.html" id="backForm" method="post" enctype="multipart/form-data">
                    <div class="form-group form-group-xs">
                        <label class="col-sm-2 text-right"><span class="required">*</span>接收人：</label>
                        <div class="col-sm-9 text-left">
                        <input id="backreceUser" name="receUser" type="hidden" >
                        <input id="backtype" name="type" type="hidden" value="2" >
                        <input id="backstatus" name="status" type="hidden" >
                            <input class=" form-control" placeholder="接收人" disabled="disabled" id="backreceUserName" type="text" >
                        </div>
                   </div>
                    <br></br>
                   <div class="form-group form-group-xs">
                        <label class="col-sm-2 text-right"><span class="required">*</span>标题：</label>
                        <div class="col-sm-9 text-left">
                            <input type="text" class="form-control"  id="backtitle" name="title" placeholder="消息标题" maxlength="250">
                        </div>
                        <br></br>
                   </div>
                    <div class="form-group form-group-xs">
                        <label class="col-sm-2 text-right"><span class="required">*</span>类型：</label>
                        <ms:btn url="/sysMessage/selectXT.html"><select class="col-sm-4 text-left" style="height: 25px;" name="type" id="type">
                       		<option value="2">用户消息</option>
                            <option value="1">系统消息</option>
                        </select></ms:btn>
                        <ms:btn url="/sysMessage/NoSelectXT.html"><select class="col-sm-4 text-left" style="height: 25px;" name="type" id="type">
                       		<option value="2">用户消息</option>
                        </select></ms:btn>
                   </div>
                   <br></br>
                   <div class="form-group form-group-xs" >
                        <label class="col-sm-2 text-right"><span class="required">*</span>内容：</label>
                        <div class="col-sm-9 text-left">
                            <textarea  class="form-control" rows="3" id="backcontent" name="content" placeholder="消息内容" maxlength="1900"></textarea>
                        </div>
                      
                   </div>
                   <br></br><br></br>
                    <div class="form-group form-group-xs">
                        <label class="col-sm-2 text-right">附件：</label>
                        <div class="col-sm-9 text-left">
                             <input type="file" id="backlicences" name="licences" style="display:inline-none;" />
                        </div>
                   </div>
                </form>
                    </div>
              <div class="modal-footer">
                  <ms:btn url="/sysMessage/save.html"><button type="button" onclick="addSave('back',0);" class="btn btn-primary btn-sm"><spring:message code="message.button.saveSpacing"/></button></ms:btn>
                  <ms:btn url="/sysMessage/messageSend.html"><button type="button" onclick="addSave('back',1);" class="btn btn-primary btn-sm">发&nbsp;送</button></ms:btn>
              </div>
            </div>
         </div>
      </div>
    </section>
    
    <%@ include file="/WEB-INF/component/commonJS.jsp" %>
    
    <script type="text/javascript">
    
  //绑定回车
	$('#titleTitle,#schType').bind('keydown', function(event) {
	if (event.keyCode == "13") {
   	 $('#selectDicCompType').click();
		}
	});	
    
    	function search(page) {
    		var titleTitle = $.trim($("#titleTitle").val());
    		var schType = $.trim($("#schType").val());
    		$("#gridlist").jqGrid('setGridParam',{  
    	        datatype:'json',
    	        postData:{"title":titleTitle, "type":schType},
    	        page : (page || 1)
    	    }).trigger("reloadGrid"); //重新载入  
    	}
    	
        $(function () {
        	$("#titleTitle").focus();//加载页面光标在第一个查询框上
        	
            $("#gridlist").jqGrid({
                url: "getSysMessageList.html",
                mtype: "post",
                datatype: "json",
                postData:{"messageStatus":"${messageStatus}"},
                autowidth: true,
                height: 345,
                colNames: [
                    '<spring:message code="message.jqGrid.cz"/>',
                    '消息标题',
					'消息内容', 
					'消息类型',
					'状态',
                ],
                colModel: [
                    { name: 'operate', width: 2, align:"center", sortable: false,
	                    formatter : function(val, opts, rowdata) {
                       	var str =  "";
                       				str+= "<ms:btn url='/sysMessage/messageLook.html'><a href='javascript:messageLook(\""+rowdata.messageId+"\");' style='background:url(${ctx}/lib/img/icon/icon.png) no-repeat -180px -20px' class='opIcon' title='查看'></a></ms:btn>"
			                   if(rowdata.readDatetime != null && rowdata.type == 2){
			                	   str+= "<ms:btn url='/sysMessage/messageBack.html'><a href='javascript:messageBack(\""+rowdata.messageId+"\");' style='background:url(${ctx}/lib/img/icon/icon.png) no-repeat -80px -80px' class='opIcon' title='回复'></a></ms:btn>"
			                   } 	
    	                return str;
                    }},
					{ name: 'title', width: 5, align:"center", sortable: false},
                    { name: 'content', width: 21, align:"center", sortable: false},
                    { name: 'type', width: 5, align: 'center', sortable: false},
                    { name: 'hasRead', width: 5, align: 'center', sortable: false }
                   
                    
                ],
                rowNum: 20,
                rowList: [10, 20, 50, 100],
                rownumbers: true,
                pager: "#gridpage",
                viewrecords: true,
                caption: '消息列表',
                jsonReader: {
                    id: "id"
                }
            });
            
            $("#gridlist").jqGrid('navGrid', '#gridpage', { add: false, edit: false, del: false, search: false, refresh: false });
            
            $(window).trigger("resize");
            
        });
        
             
             function messageLook(id){
            	 var messageId = id || "";
          		$.post("readMessage.html", {
          			messageId : messageId,
          			hasRead : 1
          		},
          		function(result) {
          			if (result.success) {
          				$.HN.dialog.opendialog(1,"消息详情","${ctx}/sysMessage/toMessageDetail.html?messageId="+id,"800px","380px",operResult);
          				 $("#gridlist").jqGrid('setGridParam',{page:1}).trigger("reloadGrid");
          			}
          			
          		}, "json");
            	 
             }
             
             function operResult(){
             } 
             
             function messageBack(id){
            	 $("#backreceUser").val("");
    				$("#backreceUserName").val("");
    				$("#backtitle").val("");
    				$("#backcontent").val("");
    				$("#backlicences").val("");
             	var messageId = id || "";
          		$.post("backMessage.html", {
          			messageId : messageId
          		},
          		function(result) {
          			if (result.success) {
          				var obj = result.rows;
          				$('.modal-title').html('消息回复');
          				$("#backreceUser").val(obj.fatherId);
           				$("#backreceUserName").val(obj.fatherName);
           				$("#backtitle").val(obj.title);
                           $('#backModal').modal({
                               keyboard: true
                           });
          			}
          			
          		}, "json");
             }
             function addUser(){
            	 $.HN.dialog.opendialog(1,"用户列表","${ctx}/sysMessage/toUserList.html","800px","500px",operHospResult);
             }
             
             function operHospResult(val){
            	 var userId="";
            	 var userName = "";
            	     		if (val.length>0) {
            	     			for(var i=0;i<val.length;i++){
            	     				userId += val[i].userId + ",";
            	     				userName += val[i].userName + ";";
            	     			}
            	 			}
        	 				$("#receUser").val(userId);
        	 				$("#receUserName").val(userName);
            	   	}
           //新增保存
             function addSave(str,status){
        	   var form = "addForm";
        	   if(str == "back"){
        		   form = "backForm"
        		   $("#backstatus").val(status);
        	   }else{
        		   $("#addstatus").val(status);
        	   }
                 if(!validate(str)){
                	 return;
                 }
                 var msg = "确定保存信息到草稿想吗？";
                 if(status == 1){
                	 msg = "确定将消息发送吗？";
                 }
                     $.HN.message.confirm(msg, '', '').on(function (e) {
                        if (e) {
                        	$("#"+form).ajaxSubmit({
                            dataType:"json",
                            success: function(result){
                                if(result.success){
                                 $.alert("<spring:message code="message.HN.alert.success"/>", "success");
                                    $("#gridlist").jqGrid('setGridParam',{page:1}).trigger("reloadGrid");
                                    if(str == 'back'){
                                    	$('#backModal').modal('hide');
                                    }
                                }else{
                                    $.alert(result.msg || "<spring:message code="message.HN.alert.fail"/>", "error");
                                        }
                                    }
                             });
                         }
                  });
             } 
           
            //校验
             function validate(str) {
            	if(str == "add"){
            		str = "";
            	}
            	 var newReceUserName = str+"receUserName";
            	 var receUserName = $.trim($("#"+newReceUserName).val());
            	 if (receUserName == null || receUserName == "") {
            		 top.$.alert("请填写消息标题名称！", "warn");
                     return false;
                 } 
                 $("#"+newReceUserName).val(receUserName);
            	 
            	var newTitle = str+"title";
                var title = $.trim($("#"+newTitle).val());
                if (title == null || title == "") {
                	 top.$.alert("请填写消息标题名称！", "warn");
                    return false;
                } 
                $("#"+newTitle).val(title);
                
                var newContent = str+"content";
                var content = $.trim($("#"+newContent).val());
                if (content == null || content == "") {
                    top.$.alert("请编写消息内容！", "warn");
                    return false;
                }
                $("#"+newContent).val(content);
                return true;
            }
            
             function showImg(imgPath, profileName) {
                 var url = "${ctx}/acctInfo/toImg.html";
                 $.HN.dialog.open({
                     "id" : "showImg",
                     "title" : profileName,
                     "url" : url,
                     "data" : {
                         "imgPath" : imgPath
                     },
                     "width" : 800,
                     "height" : 400
                 });
             }
    </script>
</body>
</html>